﻿using System.Collections.Generic;
using SW.Lite.IDAL.Master;
using SW.Lite.Infrastructure.Common;
using SW.Lite.Infrastructure.Service;
using SW.Lite.Model.Master;

namespace SW.Lite.BLL.Master
{
    public class Menu
    {
        private static readonly IMenu Dal = ServiceLocator.Instance.GetInstance<IMenu>("Master.Menu");

        /// <summary>
        ///     数据是否存在
        /// </summary>
        /// <param name="id"></param>
        public static bool Exists(int id)
        {
            return Dal.Exists(id);
        }

        /// <summary>
        ///     获取单个项
        /// </summary>
        /// <param name="id"></param>
        public static MenuModel Single(int id)
        {
            return Dal.Single(id);
        }

        /// <summary>
        ///     获取所有项目
        /// </summary>
        public static PageList<MenuModel> All()
        {
            return Dal.All();
        }

        /// <summary>
        ///     获取父菜单下的菜单列表
        /// </summary>
        /// <param name="parentId">父菜单ID</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        public static PageList<MenuModel> All(int parentId, int pageIndex, int pageSize)
        {
            return Dal.All(parentId, pageIndex, pageSize);
        }

        /// <summary>
        ///     插入数据
        /// </summary>
        /// <param name="model">单个项</param>
        public static ExecuteResult Insert(MenuModel model)
        {
            return Dal.Insert(model);
        }

        /// <summary>
        ///     更新数据
        /// </summary>
        /// <param name="model">单个项</param>
        public static ExecuteResult Update(MenuModel model)
        {
            return Dal.Update(model);
        }

        /// <summary>
        ///     更新菜单的排序号
        /// </summary>
        /// <param name="menuSorts">排序号</param>
        public static ExecuteResult UpdateSort(Dictionary<int, int> menuSorts)
        {
            return Dal.UpdateSort(menuSorts);
        }

        /// <summary>
        ///     删除数据
        /// </summary>
        /// <param name="ids"></param>
        public static ExecuteResult Delete(params int[] ids)
        {
            return Dal.Delete(ids);
        }

        /// <summary>
        ///     根据角色ID集合获取菜单列表
        /// </summary>
        /// <param name="roleIDs">角色ID集合</param>
        public static PageList<MenuModel> GetMenusByRoleIds(params int[] roleIDs)
        {
            return Dal.GetMenusByRoleIds(roleIDs);
        }

        /// <summary>
        ///     根据菜单编码获取菜单信息
        /// </summary>
        /// <param name="code">菜单编码</param>
        public static MenuModel GetMenuByCode(string code)
        {
            return Dal.GetMenuByCode(code);
        }
    }
}